package com.hele.sts.action.admin;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hele.sts.dao.UserDao;
import com.hele.sts.webwork.PageAction;
import com.opensymphony.xwork2.ActionContext;
public class UserManagerAction
  extends PageAction
{
  @Override
  public String execute()
    throws Exception
  {
    ActionContext ctx = ActionContext.getContext();
    Map session = ctx.getSession();
    String loginName = (String)session.get("AdminUser.loginName");
    if ((loginName == null) || (loginName.length() < 1))
    {
      setErrorInfo("没有登录！");
      return "error";
    }
    logger.debug(this.action);
    if ((this.action == null) || (this.action.length() < 1)) {
      return list();
    }
    if (this.action.equalsIgnoreCase("browse")) {
      return browse();
    }
    return null;
  }
  
  @Override
  public String getHref()
  {
    String href = "";
    if ((this.userName != null) && (this.userName.length() > 0)) {
      href = href + "&userName=" + this.userName;
    }
    if ((this.userId != null) && (this.userId.length() > 0)) {
      href = href + "&userId=" + this.userId;
    }
    return href;
  }
  
  @Override
  public int count()
  {
    return UserDao.count(this.userId, this.userName);
  }
  
  @Override
  public String list()
  {
    this.userList = UserDao.load(this.userId, this.userName);
    return "list";
  }
  
  public String browse()
  {
    this.userList = UserDao.browse(this.userId, this.userName);
    return "list";
  }
  
  public String getAction()
  {
    return this.action;
  }
  
  public void setAction(String action)
  {
    this.action = action;
  }
  
  public List getUserList()
  {
    return this.userList;
  }
  
  public void setUserList(List userList)
  {
    this.userList = userList;
  }
  
  public String getUserName()
  {
    return this.userName;
  }
  
  public void setUserName(String userName)
  {
    this.userName = userName;
  }
  
  public String getUserId()
  {
    return this.userId;
  }
  
  public void setUserId(String userId)
  {
    this.userId = userId;
  }
  
  public String getErrorInfo()
  {
    return this.errorInfo;
  }
  
  public void setErrorInfo(String errorInfo)
  {
    this.errorInfo = errorInfo;
  }
  
  static Logger logger = LoggerFactory.getLogger(UserManagerAction.class);
  List userList;
  String action;
  String userName;
  String userId;
  String errorInfo;
}
